use strict;
use warnings;

package Gravity::Model::Matter;
use Jifty::DBI::Schema;

use Gravity::Record schema {

    column name =>
        type is 'text',
        label is 'Name',
        is mandatory,
        is distinct,
    ;

    column description =>
        type is 'text',
        label is 'Description',
        render_as 'Textarea',
        since '0.0.3',
    ;

    column custodians =>
        references Gravity::Model::CustodianCollection
            by 'matter',
        since '0.0.2',
    ;

    column status =>
        type is 'text',
        label is 'Status',
        is mandatory,
        valid_values are [
            { display => 'Active',   value => 'active' },
            { display => 'Inactive', value => 'inactive' },
        ],
        default is 'active',
        since '0.0.4',
    ;

};

sub since { '0.0.1' }

sub after_create {
    my ( $self, $id ) = @_;

    # load newly created matter if it exists
    return unless $$id;
    $self->load($$id);

    my $tag = Gravity::Model::Tag->new;
    $tag->create(name => $self->name);

    return 1;
}

1;

